#ifndef _Cesium_BATCH_GROUP_H__
#define _Cesium_BATCH_GROUP_H__

#include "BatchGeode.h"
#include "FeatureBatchTable.h"
#include "gltfHelper.h"
#include "EdgeGenerator.h"

namespace OCPP
{
	namespace Cesium
	{
		class _Osg2CesiumExport BatchGroup : public osg::NodeVisitor
		{
		public:
			BatchGroup(gltfOptions options1, FeatureBatchTable* featureBatchTable = NULL);
			virtual ~BatchGroup();

			virtual void apply(osg::Group& node);
			virtual void apply(osg::Geode& node);

			void optimizeImage(StringStream& logMessage);
			void convert(osg::Node* node);

			BatchGeodeList& getBatchGeodeList() { return mBatchGeodeList; }
			osg::BoundingBox& boundingBox() { return mBoundingBox; }
		protected:
			gltfHelper						                        _gltfHelper;
			void submitImage();
			bool submitBatch();
		private:
			void assignBatch(osg::Geode* geode, osg::Matrix matrix, osg::StateSet* stateset, String referenceName);
			BatchGeodeMap                                           mBatchGeodeMap;
			BatchGeodeList                                          mBatchGeodeList;
			osg::BoundingBox                                        mBoundingBox;
			std::map<String, uint32>                                 mNameBatchId;
			osg::ref_ptr<EdgeGenerator>                             mEdgeGenerator;
			osg::ref_ptr<FeatureBatchTable>                         mFeatureBatchTable;

			//debug info
			std::map<String, int>                                   mImageUseCount;
			int geodeCount = 0;
			gltfOptions _gltfOptions;
			long genNameAndBatchId(osg::Geode* geode, osg::Geometry* geom, String referenceName);
		};
	}
}


#endif